//

//  ClockingWatermarkView.swift

//  WatermarkCamera

//

//  Created by 赵新 on 7/7/2024.

//

import UIKit

class ClockingWatermarkView: BaseWatermarkTemplateView {
    lazy var titleBgView: UIView = {
        let view = UIView()

        view.backgroundColor = .white

        view.layer.cornerRadius = 3

        view.layer.masksToBounds = true

        return view

    }()

    lazy var lineView: UIView = {
        let view = UIView()

        view.backgroundColor = "FF9E00".axc.uiColor

        view.layer.cornerRadius = 1

        view.layer.masksToBounds = true

        return view

    }()

    override func config() {
        super.config()

        defaultWidth = 220.cmera_autoHor

        backgroundColorView.backgroundColor = .black.axc.alpha(0.3)

        addSubview(backgroundColorView)

        addSubview(titleBgView)

        headlineLabel.layer.cornerRadius = 3

        headlineLabel.layer.masksToBounds = true

        headlineLabel.textAlignment = .center

        titleBgView.addSubview(headlineLabel)

        // 标题时间

        timinglabel.textColor = "5290FD".axc.uiColor

        timinglabel.format = .HH_mm

        timinglabel.font = 18.axc.uiFont

        timinglabel.textAlignment = .center

        titleBgView.addSubview(timinglabel)

        backgroundColorView.layer.cornerRadius = 3

        backgroundColorView.layer.masksToBounds = true

        backgroundColorView.addSubview(lineView)

        stankView.axis = .vertical

        stankView.distribution = .equalSpacing

        stankView.alignment = .fill

        stankView.spacing = 4

        addSubview(stankView)
    }

    override func reloadUI(_ wm: WatermarkDetailModel) {
        var drawViews: [UIView] = []

        headlineLabel.text = wm.name

        headlineLabel.textColor = .white

        headlineLabel.backgroundColor = "5290FD".axc.uiColor

        let item1 = createDateItem(titleStyle: .noTitle, font: 14, color: UIColor.white, dateFormat: .yyyy_MM_dd_week_HH_mm)
        let item2 = createLocationItem(titleStyle: .noTitle, font: 14, color: UIColor.white, locationFormat: .location)
        
        drawViews.append(item2)
        drawViews.append(item1)
        

        // 添加进堆栈视图

        stankView.axc.set(arrangedSubviews: drawViews)

        // 布局

        makeConstraints()
    }

    override func makeConstraints() {
        titleBgView.snp.makeConstraints { make in

            make.top.left.equalTo(8)

            make.right.equalTo(-40)

            make.height.equalTo(26.cmera_autoVer)
        }

        headlineLabel.snp.makeConstraints { make in

            make.top.left.equalTo(1)

            make.bottom.equalTo(-1)

            make.right.equalTo(titleBgView.snp.centerX)
        }

        timinglabel.snp.makeConstraints { make in

            make.left.equalTo(headlineLabel.snp.right)

            make.right.top.bottom.equalToSuperview()
        }

        super.makeConstraints()

        stankView.snp.makeConstraints { make in

            make.top.equalTo(titleBgView.snp.bottom).offset(13)

            make.left.equalTo(titleBgView.snp.left)

            make.right.equalTo(-8)

            make.bottom.equalToSuperview().offset(-8)
        }

        backgroundColorView.snp.makeConstraints { make in

            make.top.equalTo(titleBgView.snp.bottom).offset(5)

            make.left.equalTo(titleBgView)

            make.right.equalTo(-8)

            make.bottom.equalTo(stankView).offset(8)
        }

        lineView.snp.makeConstraints { make in

            make.top.left.bottom.equalTo(backgroundColorView)

            make.width.equalTo(2)
        }
    }
}
